﻿using System;
using System.Collections.Generic;
using tour.szhome.common;
using tour.szhome.map.DTO;
using TOUR.SZHOME.DAL;
using TOUR.SZHOME.Entity;
namespace TOUR.SZHOME.BLL
{
    /// <summary>
    /// 数据表Projects_Unit的业务逻辑类
    /// </summary>
    public class Projects_UnitBLL
    {
        /// <summary>
        /// 根据项目ID获取户型
        /// </summary>
        /// <param name="pid"></param>
        /// <param name="pageSet"></param>
        /// <returns></returns>
        public List<Projects_UnitEntity> GetUnitListByPID(int pid, PageSet pageSet)
        {
            string where = " XMID = " + pid;
            // 分页助手处理
            pageSet.RecordCount = Projects_UnitDAL.SearchCount(where);
            pageSet.PageCount = (int)Math.Ceiling(pageSet.RecordCount / (pageSet.PageSize * 1.0));
            return Projects_UnitDAL.Search(where, "XMID", (pageSet.PageIndex - 1) * pageSet.PageSize, pageSet.PageSize);
        }
        
        /// <summary>
        /// 根据ID删除对象
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public bool DelByID(int uid) 
        {
            return Projects_UnitDAL.Delete(uid);
        }

        /// <summary>
        /// 根据对象ID获取实体
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public Projects_UnitEntity GetUnitByID(int uid) 
        {
            return Projects_UnitDAL.GetByHXID(uid);
        }

        /// <summary>
        /// 编辑户型的逻辑方法
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool EditUnit(Projects_UnitEntity model) 
        {
            if (model.HXID > 0)
            {
                return Projects_UnitDAL.Update(model);
            }
            else
            {
                return Projects_UnitDAL.Insert(model);
            }
        }

        /// <summary>
        /// 获取最新的一条主推户型
        /// </summary>
        /// <returns></returns>
        public Projects_UnitEntity GetZTHXModel(int pid) 
        {
            return Projects_UnitDAL.GetZTHXModel(pid);
        }

        /// <summary>
        /// 根据条件获取户型列表 -- 异步
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<UnitDTO> GetHXListByAttr(int pid, int type) 
        {
            return Projects_UnitDAL.GetHXListByAttr(pid, type);
        }

        /// <summary>
        /// 获取项目 -- 户型 -- 某种Type -- 展开详情（带图） -- 暂不分页
        /// </summary>
        /// <param name="pid">项目ID</param>
        /// <param name="attr">属性： 跟据Type不同入参也不同</param>
        /// <param name="type"></param>
        /// <returns></returns>
        public List<Projects_UnitEntity> GetHXDetailByAttr(int pid, string attr, int type)
        {
            return Projects_UnitDAL.GetHXDetailByAttr(pid, attr, type);
        }
    }
}
